<?php
include '../controllers/getToeflRecommand.php';

date_default_timezone_set("PRC");

$recommandId = $_REQUEST['recommandId'];
$title = $_REQUEST['title'];
$status = $_REQUEST['status'];
$sets = getRecommandBaseSets($recommandId);
$allSets = getAllSets();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../js/recommandmanager.js"></script>
</head>
<body>

<a href="javascript:history.back(-1)">返回</a>
<hr />
<table border='2' rules='rows' cellpadding='8%' align='center'
	width='80%'>
	<tr>
		<th colspan="2">
		<h2>编辑托福机经推荐列表</h2>
		</th>
	</tr>
	<tr>
		<th>日期说明</th>
		<td><input id="title" type="text" size="100"
			value="<?php echo $title;?>"></input></td>
	</tr>
	<tr>
		<th>是否发布</th>
		<td><select id="status">
			<option value="0">不发布</option>
			<option <?php if ($status == 1) echo "selected='selected'"?>
				value="1">发布</option>
		</select></td>
	</tr>
	<tr align="center">
		<td colspan="2"><input type="button" value="修改托福机经基本信息"
			onclick="updateRecommandInfo(<?php echo $recommandId;?>);"></input></td>
	</tr>
</table>
<br />
<br />
<br />

<table border='2' rules='rows' cellpadding='8%' align='center'
	width='80%'>
	<tr>
		<th colspan="2">
		<h2>添加机经</h2>
		</th>
	</tr>
	<tr>
		<th>选择机经</th>
		<td><select id="addingSet">
		<?php
		$allSetsCount = count($allSets);
		for ($i = 0; $i < $allSetsCount; $i++) {
			$set = $allSets[$i];
			echo "<option value=".$set->setId.">".$set->name."</option>";
		}
		?>
		</select></td>

	</tr>
	<tr>
		<th>标记</th>
		<td><select id="isImportant">
			<option value="0">普通</option>
			<option value="1">小范围</option>
		</select></td>
	</tr>
	<tr align="center">
		<td colspan="2"><input type="button" value="添加机经"
			onclick="addSetToRecommand(<?php echo $recommandId;?>);"></input></td>
	</tr>
</table>

<br />
<div id="topic_list">
<table border='2' rules='rows' cellpadding='8%' align='center'
	width='80%'>
	<tr>
		<th colspan="10">
		<h2>推荐机经列表</h2>
		</th>
	</tr>
	<tr>
		<th>机经ID</th>
		<th>机经名称</th>
		<th>更新时间</th>
		<th>听力</th>
		<th>口语</th>
		<th>阅读</th>
		<th>写作</th>
		<th>标记</th>
		<th colspan="2">操作</th>
	</tr>
	<?php
	$setCount = count($sets);
	for ($i = 0; $i < $setCount; $i++) {
			
		$set = $sets[$i];
		$setId = $set->setId;
		$setName = $set->name;
		$timestamp = $set->timestamp;
		$listening = $set->listening;
		$speaking = $set->speaking;
		$reading = $set->reading;
		$writing = $set->writing;
		$isImportant = $set->isImportant;
		$formatTime = date("y-m-d h:i:s",$timestamp);
		echo "<tr align='center'><td>$setId</td><td>$setName</td><td>$formatTime</td>";
			
		if ($listening == null) {
			echo "<td>无</td>";
		}
		else {
			echo "<td>有</td>";
		}
			
		if ($speaking == null) {
			echo "<td>无</td>";
		}
		else {
			echo "<td>有</td>";
		}
			
		if ($reading == null) {
			echo "<td>无</td>";
		}
		else {
			echo "<td>有</td>";
		}
			
		if ($writing == null) {
			echo "<td>无</td>";
		}
		else {
			echo "<td>有</td>";
		}
			
		if ($isImportant == 0) {
			echo "<td><input type='button' id='remark_$setId' value='普通 （点击设为小范围）' onclick='changeMark(\"$setId\",\"$recommandId\",1);'></td>";;
		}
		else {
			echo "<td><input type='button' id='remark_$setId' value='小范围 （点击取消小范围）' onclick='changeMark(\"$setId\",\"$recommandId\",0);'></td>";
		}
			
		echo "<td><input type='button' value='修改' onclick='gotoUpdateTopic(\"$setId\");'></input>";
		echo "<input type='button' value='删除' onclick='deleteSetForRecommand($recommandId, $setId);'></input><td>";
		echo "</tr>";
	}
	?>
</table>
</div>
</body>
</html>
